#ifndef __BAG_H__
#define __BAG_H__

#include "cocos2d.h"
#include "Unit.h"
#include <map>

USING_NS_CC;
#define ITEM_VIEW_MAIN_IMAGE					95
#define ITEM_VIEW_MAIN_IMAGE_SUB_VIEW			96
#define ITEM_VIEW_SULT_VIEW_TAG					97
#define ITEM_VIEW_SULT_TAG						98
#define ITEM_VIEW_MAIN_TAG						99
#define BAG_TAG									100
#define BAG_SLOT_TAG_BEGIN						101
#define BAG_SLOT_TAG_ENDED						190
#define CHARACTER_VALUE_BACK_TAG				200
#define CHARACTER_VALUE_TAG						201
#define CHARACTER_VALUE_DETAIL_BACK_TAG			202
#define CHARACTER_VALUE_DETAIL_TAG				203

#define PLAYER_EQUIP_SLOT_START					300
#define PLAYER_EQUIP_SLOT_END					326
#define PLAYER_EQUIP_UI_TAG						299

enum ComeFrom
{
	COMEFROM_NULL,
	COMEFROM_BAG,
	COMEFROM_EQUIP,
};
class Item;
class Slot : public CCSprite
{
public:
	Slot(int ItemEntry = 0, bool _isEquipSlot = false, int EquipSlotNumber = -1);
	~Slot();

	ComeFrom GetComeFrom();
	void ReSetSlotItem()				{ m_Item = nullptr; m_ItemGuid = 0; }
	void SetItem(Item* pItem)			{ m_Item = pItem; }
	void SetItemGuid(int _ItemGuid)		{ m_ItemGuid = _ItemGuid; }
	Item* GetItem()						{ return m_Item; }
	int GetItemGuid()					{ return m_ItemGuid; }
	bool IsEmptySlot()					{ if (!m_ItemGuid) return true; return false; }
private:
	int m_ItemGuid;
	Item* m_Item;
};

class Bag : public CCSprite
{
public:
	Bag();
	~Bag();
	void SwapItem(Slot* OldSlot, Slot* NewSlot);
	void BagInit();
	std::map<int, Slot*> GetSlots()			{ return BagSlots; }
	void InitNumbers();
	void SetOwner(Player* _Owner)			{ m_owner = _Owner; }
	bool HasEmptySlot();
	int GetEmptySlot();
	Slot* GetSlot(int SlotNumber);
	int GetTouchedSlot(Vec2 pTouch);
	void LoadBagFromDB();
private:
	std::map<int, Slot*> BagSlots;
	Player* m_owner;
	CCLabelTTF* MoneyText;
	CCLabelTTF* JFText;
};

#endif